<?php
$pathToThis = pathinfo(__FILE__) ;
$retNewBlog = getcwd() ;
chdir($pathToThis['dirname']) ;

require_once "../base/Formulario.class.php" ;
require_once "../base/ParametrosAcao.class.php" ;
require_once "../componentes/InputSubmit.class.php" ;
require_once "../componentes/InputText.class.php" ;
require_once "../componentes/InputTextFckEditor.class.php" ;
require_once "../componentes/InputTextArea.class.php" ;
require_once "../util/Data.class.php" ;
require_once "../objetos/Blog.class.php" ;
require_once "../bd/Persistencia.class.php";

chdir($retNewBlog) ;

class NewBlogForm extends Formulario {
	
	/**
	 * @var InputText
	 */
	private $itTitle = null ;
	/**
	 * @var InputTextFckEditor
	 */
	private $taContent = null ;
	
	/**
	 * @var InputSubmit
	 */
	private $submit = null ;

	public function init() {
	
	}

	function NewBlogForm($nome = "NewBlogForm") {
		$this->itTitle = new InputText("Titulo", true) ;
		//$this->taContent = new InputTextArea("Conteudo", true) ; 
		$this->taContent = new InputTextFckEditor("Texto", true, null, 700, 700) ;		$this->submit = new InputSubmit("Salvar") ;
		
		$this->setAction("salva") ;
		$this->setNome($nome) ;
	}

	public function executaSalva(ParametrosAcao $parametrosAcao) {
		if (! $this->valida()) {
			return null ;
		}
		
		$blog = new Blog() ;
		$blog->setTitle($this->itTitle->getValorConvertido()) ;
		$data = date("Y-m-d H:i:s", time()) ;
		$blog->setPostTime($data) ;
		$blog->setContent($this->taContent->getValorConvertido()) ;
		
		$p = Persistencia::getInstance();
		$p->insere($blog);
		
		$this->reseta();
		
		return "showBlogs.php" ;
	}

	public function getPhp() {
		return "newBlog.php" ;
	}

	/**
	 * @return InputText
	 */
	public function getItTitle() {
		return $this->itTitle ;
	}

	/**
	 * @return InputSubmit
	 */
	public function getSubmit() {
		return $this->submit ;
	}

	/**
	 * @return InputTextFckEditor
	 */
	public function getTaContent() {
		return $this->taContent ;
	}

	/**
	 * @param InputText $itTitle
	 */
	public function setItTitle($itTitle) {
		$this->itTitle = $itTitle ;
	}

	/**
	 * @param InputSubmit $submit
	 */
	public function setSubmit($submit) {
		$this->submit = $submit ;
	}

	/**
	 * @param InputTextFckEditor $taContent
	 */
	public function setTaContent($taContent) {
		$this->taContent = $taContent ;
	}

}
?>